//
//  CEMineHeaderView.m
//  digitalCurrency
//
//  Created by 来迎宾 on 2019/4/4.
//  Copyright © 2019年 XinHuoKeJi. All rights reserved.
//

#import "CEMineHeaderView.h"

@implementation CEMineHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor blackColor];
        
        [self createviews];
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(nonnull NSString *)key {
    NSLog(@"value:%@ _ key:%@",value,key);
}

- (void)createviews {
    CGFloat statusHeight = kStatusBarHeight;
    
    UIImageView *headerbg = [[UIImageView alloc] init];
    headerbg.image = ImageName(@"d_head_bg");
    [self addSubview:headerbg];
    [headerbg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(10);
        make.left.top.mas_equalTo(-10);
        make.bottom.equalTo(0);
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.text = LocalizationKey(@"Mine");
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:18];
    label.textColor = [UIColor whiteColor];
    [headerbg addSubview:label];
    self.mineTitle = label;
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.mas_equalTo(0);
        make.top.mas_equalTo(statusHeight);
        make.height.mas_equalTo(44);
    }];
    self.mineTitle.hidden = YES;
    
    UIImageView *headerimg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user_photo"]];
    headerimg.backgroundColor = [UIColor whiteColor];
    headerimg.layer.cornerRadius  = 38.0;
    headerimg.layer.masksToBounds = YES;
    [self addSubview:headerimg];
    [headerimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(33);
        make.top.mas_equalTo(SafeAreaTopHeight);
        make.height.width.mas_equalTo(76);
    }];
    
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.text = @"";
    nameLabel.textColor = [UIColor whiteColor];
    nameLabel.font = kFontPF_Medium(17);
    [self addSubview:nameLabel];
    self.nameLabel = nameLabel;
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(headerimg.mas_right).mas_offset(18);
        make.centerY.mas_equalTo(headerimg);
    }];
    
    UILabel *copText = [[UILabel alloc] init];
    [self addSubview:copText];
    copText.text = @"";
    copText.font = kFontPF_Medium(17);
    copText.textColor = [UIColor whiteColor];
    self.copText = copText;
    [copText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(headerimg.mas_left);
        make.top.mas_equalTo(headerimg.mas_bottom).offset(36);
        make.width.lessThanOrEqualTo(170);
    }];
    
    UIButton *copBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    copBtn.tintColor = [UIColor colorWithHEX:maincolor];
    [copBtn setImage:[UIImage imageNamed:@"m_copy"] forState:UIControlStateNormal];
    [self addSubview:copBtn];
    self.copBtn = copBtn;
    [copBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(copText.mas_right).mas_offset(5);
        make.centerY.mas_equalTo(copText);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(20);
    }];
    
    //yaoqinghaoyou
    
    UIButton *yaoQingBtn = [[UIButton alloc]init];
    [self addSubview:yaoQingBtn];
    [yaoQingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(-32);
        make.centerY.equalTo(copText);
        make.height.equalTo(28);
    }];
    [yaoQingBtn setTitle:[NSString stringWithFormat:@"   %@   ",LocalizationKey(@"邀请好友")] forState:UIControlStateNormal];
    [yaoQingBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    yaoQingBtn.titleLabel.font = kFont(12);
    yaoQingBtn.layer.cornerRadius = 14.0;
    yaoQingBtn.layer.borderWidth = 1;
    yaoQingBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [yaoQingBtn addTarget:self action:@selector(yaoqing:) forControlEvents:UIControlEventTouchUpInside];
    
//    UIImageView *yaoqing = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_yao"]];
//    yaoqing.clipsToBounds = YES;
//    yaoqing.contentMode = UIViewContentModeScaleAspectFit;
//    [self addSubview:yaoqing];
//    yaoqing.userInteractionEnabled = YES;
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yaoqing:)];
//    [yaoqing addGestureRecognizer:tap];
//
//    [yaoqing mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(headerimg.mas_bottom).mas_offset(30);
//        make.left.mas_equalTo(15);
//        make.height.mas_equalTo(110);
//        make.width.mas_equalTo(SCREEN_WIDTH-30);
//    }];
    
//    UILabel *yaoTips1 = [[UILabel alloc] init];
//    [yaoqing addSubview:yaoTips1];
//    yaoTips1.text = LocalizationKey(@"Invite Friends");
//    yaoTips1.font = [UIFont systemFontOfSize:14];
//    yaoTips1.textColor = [UIColor whiteColor];
//    self.yaoTips1 = yaoTips1;
//    [yaoTips1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(100);
//        make.top.mas_equalTo(30);
//        make.height.mas_equalTo(16);
//    }];
//    UILabel *yaoTips2 = [[UILabel alloc] init];
//    [yaoqing addSubview:yaoTips2];
//    yaoTips2.text = LocalizationKey(@"CT award for Invitation");
//    yaoTips2.font = [UIFont systemFontOfSize:14];
//    yaoTips2.textColor = [UIColor whiteColor];
//    self.yaoTips2 = yaoTips2;
//    [yaoTips2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(100);
//        make.top.mas_equalTo(60);
//        make.height.mas_equalTo(16);
//    }];
    
}
    
- (void)yaoqing:(UITapGestureRecognizer *)tap {
    NSLog(@"%@",tap);
    if (self.addFriendBlock) {
        self.addFriendBlock();
    }
}

@end
